package cn.anc.aonicardv.util;

import java.util.List;

import cn.anc.aonicardv.Constant;
import cn.anc.aonicardv.widget.AlbumDecoration;

/**
 * Created by yangdai on 2017/8/2.
 */

public class AoniBeanDecorationUtils {

    public static int getDirectionByItemPosition(List<AlbumDecoration.DecorationBean> decorationBeanList, int position) {
        if (decorationBeanList == null)
            return -1;
        for (int i = 0; i < decorationBeanList.size(); i++) {
            if (position >= decorationBeanList.get(i).position && position < decorationBeanList.get(i).position + decorationBeanList.get(i).itemCount) {
                int temp = position - decorationBeanList.get(i).position;
                if (temp % 3 == 0) {
                    return Constant.DecorationParam.LEFT;
                } else if (temp % 3 == 1) {
                    return Constant.DecorationParam.MIDDLE;
                } else
                    return Constant.DecorationParam.RIGHT;
            }
        }

        return position;
    }


    public static int getSpanSize(List<AlbumDecoration.DecorationBean> decorationBeanList, int position) {
        int cur_group = -1;
        if (decorationBeanList.size()==0){
            return 1;
        }
        if (position < decorationBeanList.get(0).itemCount) {
            cur_group = 0;
        } else {
            for (int i = 1; i < decorationBeanList.size(); i++) {
                if (position >= (decorationBeanList.get(i - 1).position + decorationBeanList.get(i - 1).itemCount)
                        && (position < decorationBeanList.get(i).position + decorationBeanList.get(i).itemCount)) {
                    cur_group = i;
                    break;
                }
            }
        }
        if (cur_group < 0) {
            return 1;
        }
        int last_line_count = decorationBeanList.get(cur_group).itemCount % 3;
        if (last_line_count != 0) {
            if (position == (decorationBeanList.get(cur_group).position + decorationBeanList.get(cur_group).itemCount - 1)) {
                if (last_line_count == 1) {
                    return 3;
                }
                return 2;
            }
        }
        return 1;
    }


}
